package com.xayy.scheduled.controller;


import cn.kawins.base.result.ResultBody;
import com.github.pagehelper.PageInfo;
import com.xayy.scheduled.service.DataInfoService;
import com.xayy.scheduled.model.DataInfo;
import com.xayy.scheduled.model.dto.DataInfoDto;
import com.xayy.scheduled.model.vo.DataInfoVo;
import com.xayy.scheduled.convert.DataInfoConvert;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import lombok.AllArgsConstructor;
import javax.validation.Valid;
import java.util.List;

import java.io.Serializable;
import java.util.List;

/**
*  controller
*
* @ClassName: DataInfoController
* @Description: 控制层访问接口
* @author liuyuan
* @date 2025-06-27
*/
@Api(tags="数据信息表接口管理")
@RestController
@AllArgsConstructor
@RequestMapping("/api/v1.0/dataInfo1")
public class DataInfoController  {
    private final  DataInfoService dataInfoService;

    @PostMapping({"/page"})
    @ApiOperation(value = "分页")
    public ResultBody page(@RequestBody DataInfoDto query){
        PageInfo<DataInfoVo> page = dataInfoService.page(query);

        return ResultBody.success(page);
    }

    @GetMapping({"/list"})
    @ApiOperation(value = "获取列表")
    public ResultBody list(DataInfoDto query){
        List<DataInfoVo> list=dataInfoService.listByDTO(query);

        return ResultBody.success(list);
    }

    @GetMapping("{id}")
    @ApiOperation(value = "获取信息")
    public ResultBody get(@PathVariable("id") Long id){
        DataInfo entity = dataInfoService.selectById(id);

        return ResultBody.success(DataInfoConvert.INSTANCE.convert(entity));
    }

    @PostMapping({"/save"})
    @ApiOperation(value = "保存")
    public ResultBody save(@RequestBody DataInfoVo vo){
        DataInfo info = dataInfoService.save(vo);
        if (null == info){
            return ResultBody.failed("数据编码不能重复");
        }else
            return ResultBody.success();
    }

    @PutMapping({"/update"})
    @ApiOperation(value = "修改")
    public ResultBody update(@RequestBody DataInfoVo vo){
        DataInfo entity = dataInfoService.update(vo);
        return (entity != null) ? ResultBody.success(entity) : ResultBody.failed("更新失败");
    }

    @DeleteMapping({"/delete"})
    @ApiOperation(value = "删除")
    public ResultBody delete(@RequestBody List<Long> idList){
        dataInfoService.delete(idList);

        return ResultBody.success();
    }

}